﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using MvcDesign.Core.CoreDataModel;

namespace MvcDesign.Core.DataAccess
{
    public class ObjectCollection<T> : IQueryable<T> where T: class, IDataObject
    {
        private readonly DbSet<T> _collection;

        public ObjectCollection(DbSet<T> collection)
        {
            _collection = collection;
        }

        public IEnumerator<T> GetEnumerator()
        {
            return ((IEnumerable<T>) _collection).GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public Expression Expression
        {
            get { return ((IQueryable<T>) _collection).Expression; }
        }

        public Type ElementType
        {
            get { return ((IQueryable<T>) _collection).ElementType; }
        }

        public IQueryProvider Provider
        {
            get { return ((IQueryable<T>) _collection).Provider; }
        }

        public T Add(T obj)
        {
            return _collection.Add(obj);
        }

        public T Remove(T obj)
        {
            return _collection.Remove(obj);
        }

        public T Create()
        {
            return _collection.Create();
        }

        public T Attach(T obj)
        {
            return _collection.Attach(obj);
        }

        public T Find(params object[] keyValues)
        {
            return _collection.Find(keyValues);
        }
    }
}
